﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Editing;
using System.Windows.Documents;

namespace ExORMDesginer.UserControls.CCodeEditer
{
    public static class WordUtilities
    {
        public static string FindPreviousWord(TextArea textArea)
        {
            int startOfWord = TextUtilities.GetNextCaretPosition(textArea.Document, textArea.Caret.Offset, LogicalDirection.Backward, CaretPositioningMode.WordStart);

            int endOfWord = TextUtilities.GetNextCaretPosition(textArea.Document, textArea.Caret.Offset, LogicalDirection.Backward,
                                                               CaretPositioningMode.WordBorderOrSymbol);

            if (endOfWord <= startOfWord) return null;

            return textArea.Document.GetText(startOfWord, endOfWord - startOfWord);
        }

        public static string GetDotPreviousWord(TextArea textArea)
        {
            
            int startOfWord = TextUtilities.GetNextCaretPosition(textArea.Document, textArea.Caret.Offset - 1, LogicalDirection.Backward, CaretPositioningMode.WordStart);

            int endOfWord = textArea.Caret.Offset - 1;

            if (endOfWord <= startOfWord) return null;

            return textArea.Document.GetText(startOfWord, endOfWord - startOfWord);


        }

    }
}
